package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "Sku管理")
@RestController
@RequestMapping("admin/product")
public class SkuManageController {
    @Autowired
    private ManageService manageService;

    @ApiOperation(value = "sku的保存")
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    @ApiOperation(value = "分页sku查询列表")
    @GetMapping("list/{page}/{limit}")
    public Result getSkuList(@PathVariable Long page,@PathVariable Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page,limit);
        IPage<SkuInfo> iPage = manageService.getSkuList(skuInfoPage);
        return Result.ok(iPage);
    }

    @ApiOperation(value = "Sku商品上架BySkuId")
    @GetMapping("onSale/{skuId}")
    public Result onSaleBySkuId(@PathVariable Long skuId){
        manageService.onSaleBySkuId(skuId);
        return Result.ok();
    }

    @ApiOperation(value = "商品下架BySkuId")
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSaleBySkuId(@PathVariable Long skuId){
        manageService.cancelSaleBySkuId(skuId);
        return Result.ok();
    }

}
